package com.songshuai.webapi.crm.controller;

import com.songshuai.webapi.common.redis.RedisUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class BaseController {

    @Autowired
    protected RedisUtil redisUtil;


    /*
   获取当前登录用户的用户名
    */
    protected String getUserName() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Object principal = authentication.getPrincipal();
        String name= String.valueOf(principal);
        return  name;
    }

    protected String getToken(){
        String id=  redisUtil.getString(getUserName());
        if(StringUtils.isBlank(id)){
            return null;
        }else{
            return redisUtil.getString(id);
        }
    }

}
